package quq.missq.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.android.volley.toolbox.NetworkImageView;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

import quq.missq.BaseActivity;
import quq.missq.Constants;
import quq.missq.R;
import quq.missq.adapter.BigShootDetailAdapter;
import quq.missq.beans.BigShootDetailBean;
import quq.missq.beans.CommentsBean;
import quq.missq.beans.UserBean;
import quq.missq.utils.UserTools;
import quq.missq.utils.VolleyTool;
import quq.missq.views.LoadMoreListView;

/**
 * Created by River on 8/3/15.
 */
public class BigShootDetailMediaActivity extends BaseActivity implements View.OnClickListener{


    private WebView mWebView;
    private ImageView mBack;
    private TextView mHeadTitle;
    private String path = "";
    private String headTitle = "";
    private RelativeLayout videoView;
    private View xCustomView;
    private WebChromeClient.CustomViewCallback     xCustomViewCallback;
    private MyWebChromClient webChromeClient;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.big_shoot_detail_media_activity);
        path = getIntent().getExtras().getString("path");
        headTitle = getIntent().getExtras().getString("headTitle");
        initView();
        initListener();
        initData();
    }

    private void initView(){
        mWebView = (WebView)findViewById(R.id.webView);
        mHeadTitle = (TextView)findViewById(R.id.head_title);
        mBack = (ImageView)findViewById(R.id.back);
        videoView = (RelativeLayout) findViewById(R.id.videoview);
    }

    private void initListener(){
        mBack.setOnClickListener(this);
    }

    private void initData(){
        mHeadTitle.setText(headTitle);
      //  mWebView.loadDataWithBaseURL(path,"","text/html","utf-8","");
        mWebView.setWebChromeClient(new MyWebChromClient());
        mWebView.setWebViewClient(new WebViewClient());
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setDomStorageEnabled(true);
        mWebView.setLayerType(WebView.LAYER_TYPE_HARDWARE, null);
        mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
        mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        mWebView.getSettings().setAllowFileAccess(true);
        mWebView.getSettings().setDefaultTextEncodingName("UTF-8");
        mWebView.getSettings().setLoadWithOverviewMode(true);
        mWebView.getSettings().setUseWideViewPort(true);
        mWebView.setVisibility(View.VISIBLE);
        mWebView.loadUrl(path);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back:
                finish();
                break;

         }
    }
    class MyWebChromClient extends WebChromeClient{
        @Override
        public void onShowCustomView(View view, CustomViewCallback callback) {

            if (xCustomView != null) {
                callback.onCustomViewHidden();
                return;
            }
            videoView.setVisibility(View.VISIBLE);

            videoView.addView(view);
            xCustomView = view;
            mWebView.setVisibility(View.INVISIBLE);
            xCustomViewCallback = callback;
        }
        public void onHideCustomView() {

            if (xCustomView == null){
                return;
            }
            // Hide the custom view.
            xCustomView.setVisibility(View.GONE);

            // Remove the custom view from its container.
            videoView.removeView(xCustomView);

            xCustomView = null;
            videoView.setVisibility(View.GONE);
            xCustomViewCallback.onCustomViewHidden();

            mWebView.setVisibility(View.VISIBLE);

        }
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mWebView.destroy();
    }
}
